import java.util.Scanner;

public class Main {
    public int romanToInt(String s) {
        Map<String,Integer> map=new HashMap<>();
        map.put("I",1);
        map.put("V",5);
        map.put("X",10);
        map.put("L",50);
        map.put("C",100);
        map.put("D",500);
        map.put("M",1000);
        StringBuilder sb=new StringBuilder(s);
        int result=0;
        for(int i=0;i<sb.length();i++){
            char a=sb.charAt(i);
            if(sb.length()>=2&&i>0){
                if((a=='V'||a=='X')&&sb.charAt(i-1)=='I'){
                    result-=2;
                }
                if((a=='L'||a=='C')&&sb.charAt(i-1)=='X'){
                    result-=20;
                }
                if((a=='D'||a=='M')&&sb.charAt(i-1)=='C'){
                    result-=200;
                }
            }
            result=result+map.get(String.valueOf(a));
        }
        return result;
    }
    }

}
